(function(angular) {
	'use strict';
	angular.module("fs.waf").factory("assetService", assetService)
	.filter("frReqStatus", [ '$filter', '$locale', 'assetService', function($filter, $locale, assetService) {
		return function(frReqStatus, pattern) {
			return $filter('translate')(assetService.frReqStatusFilter(frReqStatus, pattern));
		};
	} ])
	.filter("assetStatus", [ '$filter', '$locale', 'assetService', function($filter, $locale, assetService) {
		return function(assetStatus, pattern) {
			return $filter('translate')(assetService.assetStatusFilter(assetStatus, pattern));
		};
	} ]);
	assetService.$inject = [ '$q', 'loggerFactory', 'ajaxServiceFactory' ];
	function assetService($q, loggerFactory, ajaxServiceFactory) {
		var log = loggerFactory.getLogger("assetService");
		var ajaxServices = ajaxServiceFactory.buildAjaxService({
			getAssetListOptions: {
				url: 'do/apf/dataList/getAssetListOptions',
				method: 'get'
			},
			getAssetViewOptions: {
				url: 'do/apf/dataList/getAssetViewOptions',
				method: 'get'
			}
		});	
		
		var _assetStatus = null;
		
		function getAssetListOptions() {
			var defer = $q.defer();
			ajaxServices.getAssetListOptions().then(function(response) {
				_assetStatus = response.data.assetStatus;
				defer.resolve(response.data);
			});
			return defer.promise;
		}
		
		function getAssetViewOptions() {
			var defer = $q.defer();
			ajaxServices.getAssetViewOptions().then(function(response) {
				defer.resolve(response.data);
			});
			return defer.promise;
		}
		
		function frReqStatusFilter(optionValue) {
			var options = _frReqStatus;
			var optionLabel = '';
			if(options) {
				angular.forEach(options.data, function(obj, index) {
					if(optionValue == obj.value) {
						optionLabel = obj.label;
					}
				});
			}
			return optionLabel;
		}
		
		function assetStatusFilter(optionValue) {
			var optionLabel = '';
			if(_assetStatus) {
				angular.forEach(_assetStatus, function(obj, index) {
					if(optionValue == obj.value) {
						optionLabel = obj.label;
					}
				});
			}
			return optionLabel;
		}
		
		function invoiceStatusFilter(optionValue) {
			var options = _invoiceStatus;
			var optionLabel = '';
			if(options) {
				angular.forEach(options.data, function(obj, index) {
					if(optionValue == obj.value) {
						optionLabel = obj.label;
					}
				});
			}
			return optionLabel;
		}
		
		return {
			getAssetListOptions : getAssetListOptions,
			getAssetViewOptions : getAssetViewOptions,
			frReqStatusFilter : frReqStatusFilter,
			assetStatusFilter : assetStatusFilter,
			invoiceStatusFilter : invoiceStatusFilter
		};
	}
})(angular);